package com.ruoyi.dev.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dev.domain.DevApi;
import com.ruoyi.dev.service.IDevApiService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 接口信息Controller
 * 
 * @author yepanpan
 * @date 2025-02-25
 */
@RestController
@RequestMapping("/dev/api")
public class DevApiController extends BaseController
{
    @Autowired
    private IDevApiService devApiService;

    /**
     * 查询接口信息列表
     */
    @PreAuthorize("@ss.hasPermi('dev:api:list')")
    @GetMapping("/list")
    public TableDataInfo list(DevApi devApi)
    {
        startPage();
        List<DevApi> list = devApiService.selectDevApiList(devApi);
        return getDataTable(list);
    }

    /**
     * 导出接口信息列表
     */
    @PreAuthorize("@ss.hasPermi('dev:api:export')")
    @Log(title = "接口信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DevApi devApi)
    {
        List<DevApi> list = devApiService.selectDevApiList(devApi);
        ExcelUtil<DevApi> util = new ExcelUtil<DevApi>(DevApi.class);
        util.exportExcel(response, list, "接口信息数据");
    }


    /**
     * 获取接口信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('dev:api:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(devApiService.selectDevApiById(id));
    }

    /**
     * 新增接口信息
     */
    @PreAuthorize("@ss.hasPermi('dev:api:add')")
    @Log(title = "接口信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody DevApi devApi)
    {
        return toAjax(devApiService.insertDevApi(devApi));
    }

    /**
     * 修改接口信息
     */
    @PreAuthorize("@ss.hasPermi('dev:api:edit')")
    @Log(title = "接口信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody DevApi devApi)
    {
        return toAjax(devApiService.updateDevApi(devApi));
    }

    /**
     * 删除接口信息
     */
    @PreAuthorize("@ss.hasPermi('dev:api:remove')")
    @Log(title = "接口信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(devApiService.deleteDevApiByIds(ids));
    }
}
